import axios from 'axios'



import { ElMessage } from 'element-plus'


export const PATH_URL = import.meta.env.VITE_API_BASE_PATH



const axiosInstance = axios.create({
  baseURL: PATH_URL,
  timeout: 8000,
});

axiosInstance.interceptors.request.use(function (req) {
  // 在发送请求之前做些什么
  // const headers = req.headers
  // if(headers.Authorization) headers.Authorization = 'Bear Jack'




  return req;
});

axiosInstance.interceptors.response.use(function (res) {
  const { code, data, msg } = res.data
  if(code === 200) {
    return data;
  } else if(code === 40001) {
    ElMessage.error(msg)
    setTimeout(() => {
      router.push('/login')
    }, 15000);
    return Promise.reject(msg);
  } else {
    ElMessage.error(msg)
    return Promise.reject(msg);
  }  
});